<?php
final class Result {
	private $modulename = '';
	private $status = 401;
	private $errorcode = -1;

	public function setModulename ($modulename) {
		$this->modulename = $modulename;
	}

	public function setErrorCode ($errorcode) {
		$this->errorcode = $errorcode;
	}

	public function setStatus ($status) {
		$this->status = $status;
	}

	public function Create ($callback = NULL) {
		$dom = new DOMDocument ('1.0', 'utf-8');
		$dom->formatOutput = true;

		$root = $dom->createElement ('CyberMedia');
		$root->setAttribute ('version', 1); //API version
		$root->setAttribute ('status', $this->status);


		if ($this->modulename != '') {
			$result = $dom->createElement ('result');
			$result->setAttribute ('module', $this->modulename);
			$result->setAttribute ('errorcode', $this->errorcode);
			$root->appendChild ($result);
			if ($callback != NULL) {
				call_user_func ($callback, $dom, $result);
			}
		}
		$dom->appendChild ($root);
		return $dom->saveXML ();
	}
}
?>